<?php
session_start();
require_once('recaptchalib.php');

$privatekey = "6LfeJsUSAAAAANNIs_s5xgKKkMff7CySlldx5iXq";
$resp = recaptcha_check_answer ($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }



function spamcheck($field)
  {
  //filter_var() sanitizes the e-mail
  //address using FILTER_SANITIZE_EMAIL
  $field=filter_var($field, FILTER_SANITIZE_EMAIL);

  //filter_var() validates the e-mail
  //address using FILTER_VALIDATE_EMAIL
  if(filter_var($field, FILTER_VALIDATE_EMAIL))
    {
    return TRUE;
    }
  else
    {
    return FALSE;
    }
  }

for($i = 1; $i <= 10; $i++){
	if (isset($_REQUEST['email'.$i.''])){
		//$mailcheck = spamcheck($_REQUEST['email']);
		if (false)
    	{
  	 //	 	echo "Invalid input";
 	  }
		
		else
    	{//send email
    		$email = $_REQUEST['email1'] ;
    $subject = "Invitation to join your friends league" ;
    $message = $_REQUEST['message'] ;
    mail($email, "Subject: $subject",
    $message, "From: Brandon" );
    echo "Thank you for using our mail form";
    }
	}	
	
	else{
		break;
	}
}

if (isset($_REQUEST['email']))
{//if "email" is filled out, proceed

  //check if the email address is invalid
  
  
  
  }
?>